package org.icnmasjid.member.webapp.action;

import java.security.InvalidParameterException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.icnmasjid.member.service.ImportIcnDataManager;
import org.springframework.web.servlet.ModelAndView;

public class ImportIcnDataController extends BaseFormController {

	private ImportIcnDataManager importIcnDataManager;

	protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
		ModelAndView mav = new ModelAndView("importReport");
		/*
		String all = request.getParameter("all");
		importIcnDataManager.importIcnPayments(StringUtils.isNotBlank(all));
		*/
		//importIcnDataManager.importOnlineSchoolRegistration();
	 	String mode = request.getParameter("mode");
	    if ( StringUtils.isBlank(mode) ) {
	    	throw new InvalidParameterException("mode must be either moodle-sync or school-fees or new-reg or afa-reg");
	    }
	    if ("school-fees".equalsIgnoreCase(mode)) {
	    	importIcnDataManager.importSchoolFees();
	    } 
	    if ( "moodle-sync".equalsIgnoreCase(mode) ) {
	    	importIcnDataManager.importMoodleGrade();
	    }
	    if ( "new-reg".equalsIgnoreCase(mode) ) {
	    	importIcnDataManager.importOnlineSchoolRegistration();
	    }
	    if ( "afa-reg".equalsIgnoreCase(mode) ) {
	    	importIcnDataManager.importAfaRegistration();
	    }

		return mav;
	}

	public ImportIcnDataManager getImportIcnDataManager() {
		return importIcnDataManager;
	}

	public void setImportIcnDataManager(ImportIcnDataManager importIcnDataManager) {
		this.importIcnDataManager = importIcnDataManager;
	}

}
